<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{msg}}</h1>
    </div>
    <script>
        const vm  = new Vue({
            el:"#app",
            data(){
                return{
                    msg:"I love you"
                };   
            }
        })
        
//1.写成对象的缺点：因为组件进行复用的时候，多出地方要对data进行操作，因为data1_one data1_two data1 地址都是一样的，修改一个其余都会产生变化
//组件之间的data会产生影响
        const data1 = {
            name:"zhangsan",
            age:18,
        };
        const data1_one = data1;
        const data1_two = data1;
        data1_two.age = 60;
        console.log(data1_one);
        console.log(data1_two);

//2.写成函数：组件复用的时候，拿到data2中的数据，调用data2函数
//在函数调用的时候，每一次调用都会创建一个新对象，组件之间的data不会产生影响。
        function data2(){
            const obj={
                name:"zhangsan",
                age:18
            };
            return obj;
        }
        const data2_one = data2();
        data2_one.name = "wangwu";
        console.log(data2_one)
        const data2_two = data2();
        data2_two.age = 20;
        console.log(data2_two)

    </script>
</body>
</html>